﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kyers.DataEntity;
using System.Data;
namespace BaseEntity.PosgresQL
{
    public class BaseEntity
    {
        /// <summary>
        /// contructor for start connect DB that not use connection, it will auto get from config file
        /// </summary>
        public BaseEntity()
        {
            if(DBContext==null)
             DBContext = new KyersSoftWarePosgresQLBaseEntity();
        }
        static KyersSoftWarePosgresQLBaseEntity DBContext { get; set; }

        public static KyersSoftWarePosgresQLBaseEntity DBModel()
        {
            return DBContext;
        }
        public static void StartDB(string connection)
        {
            if (DBContext == null)
            {
                DBContext = new KyersSoftWarePosgresQLBaseEntity(connection);
                DBContext.Connect();
            }
        }
        public static void StartDB()
        {
            if (DBContext == null)
            {
                DBContext = new KyersSoftWarePosgresQLBaseEntity();
                DBContext.Connect();
            }
        }
        public static void StopDB()
        {
            DBContext = null;
           
        }

        public static bool TestConnect(string connectionstring)
        {
            KyersSoftWarePosgresQLBaseEntity DBContextTest = new KyersSoftWarePosgresQLBaseEntity(connectionstring, true);
            DBContextTest.Connect();
            if(DBContextTest.ConnectState ==KyersSoftWarePosgresQL_Stasus.Connected)
            {
                return true;
            }
            return false;
        }
    }
}
